package com.ycd.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.ycd.domain.User;
import com.ycd.fallback.OrderFallback;
import com.ycd.feigens.UserFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    // 注入feign接口
    @Autowired
    private UserFeignClient userFeignClient;

    /*
     * @Description: 调用user服务接口并返回
     **/
    @GetMapping("/getById/{id}")
    // fallback-当前类
    // fallbackClass-指定类
    /*@SentinelResource(value="order-getById", fallback = "fuseDegradation",
            fallbackClass = OrderFallback.class)*/
    public User getById(@PathVariable("id") Long id){
        // 调用OpenFeign接口，通信User服务
        return userFeignClient.getById(id);
    }
   /* public User fuseDegradation(@PathVariable("id") Long id,Throwable e){
        e.printStackTrace();
        return new User(-1L, "当前类熔断降级触发！", "服务不可用，请稍后重试！");
    }*/


}